package com.fatri.lessionsimple.util.study


class Test {
    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
//            Zoo(Dog()).bark()
            val map = mapOf<Int, String>(1 to "111", 2 to "222", 3 to "333")
            for ((k, v) in map) {
                println("k=$k,v=$v")
            }

            val list = listOf<String>("11", "22", "33", "44", "55", "66")
            for ((index, value) in list.withIndex()) {
                println("$index,$value")
            }


            /**
             * 集合操作符
             */
            val a = arrayOf("4", "0", "7", "i", "f", "w", "0", "9")
            val index = arrayOf(5, 3, 9, 4, 8, 3, 1, 9, 2, 1, 7)

            index.filter { it < a.size }    //过滤，返回Array<Int>
                .map { a[it] }  //转换数据类型
                .reduce { acc, s -> "$acc-$s" }  //每相邻两个元素的拼接方式，返回stirng
                .also {
                    println(it)
                }



            for (i in 1..100){
                print("$i " )
                    i vs  2   //中缀表达式

            }
        }
    }

    interface Animal {
        fun bark()
    }

    class Dog : Animal {
        override fun bark() {
            println("Dog wang")
        }

    }

    /**
     * bys实现代理，kt动态代理本质上是转换成静态代理
     * 1、Zoo没有实现bark方法，则参数作为代理对象
     */
    class Zoo(animal: Animal) : Animal by animal {
//        override fun bark() {
//            println("Zoo bark")
//        }

    }
}

/**
 * infix声明中缀表达式符号
 */
infix fun Int.vs(int: Int){}
